<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>The N-dimensional array (ndarray) &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../about.html" >
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../index.html" >
    <link rel="up" title="Array objects" href="arrays.html" >
    <link rel="next" title="numpy.ndarray" href="generated/numpy.ndarray.html" >
    <link rel="prev" title="Array objects" href="arrays.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../index.html">
      <img border=0 alt="NumPy" src="../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="index.html" >NumPy Reference</a></li>
          <li class="active"><a href="arrays.html" accesskey="U">Array objects</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="generated/numpy.ndarray.html" title="numpy.ndarray"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="arrays.html" title="Array objects"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The N-dimensional array (<code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code>)</a><ul>
<li><a class="reference internal" href="#constructing-arrays">Constructing arrays</a></li>
<li><a class="reference internal" href="#indexing-arrays">Indexing arrays</a></li>
<li><a class="reference internal" href="#internal-memory-layout-of-an-ndarray">Internal memory layout of an ndarray</a></li>
<li><a class="reference internal" href="#array-attributes">Array attributes</a><ul>
<li><a class="reference internal" href="#id1">Memory layout</a></li>
<li><a class="reference internal" href="#data-type">Data type</a></li>
<li><a class="reference internal" href="#other-attributes">Other attributes</a></li>
<li><a class="reference internal" href="#array-interface">Array interface</a></li>
<li><a class="reference internal" href="#ctypes-foreign-function-interface"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code> foreign function interface</a></li>
</ul>
</li>
<li><a class="reference internal" href="#array-methods">Array methods</a><ul>
<li><a class="reference internal" href="#array-conversion">Array conversion</a></li>
<li><a class="reference internal" href="#shape-manipulation">Shape manipulation</a></li>
<li><a class="reference internal" href="#item-selection-and-manipulation">Item selection and manipulation</a></li>
<li><a class="reference internal" href="#calculation">Calculation</a></li>
</ul>
</li>
<li><a class="reference internal" href="#arithmetic-matrix-multiplication-and-comparison-operations">Arithmetic, matrix multiplication, and comparison operations</a><ul>
</ul>
</li>
<li><a class="reference internal" href="#special-methods">Special methods</a><ul>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="arrays.html"
                        title="previous chapter">Array objects</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="generated/numpy.ndarray.html"
                        title="next chapter">numpy.ndarray</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="the-n-dimensional-array-ndarray">
<span id="arrays-ndarray"></span><h1>The N-dimensional array (<code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code>)<a class="headerlink" href="#the-n-dimensional-array-ndarray" title="Permalink to this headline">¶</a></h1>
<p>An <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> is a (usually fixed-size) multidimensional
container of items of the same type and size. The number of dimensions
and items in an array is defined by its <a class="reference internal" href="generated/numpy.ndarray.shape.html#numpy.ndarray.shape" title="numpy.ndarray.shape"><code class="xref py py-attr docutils literal notranslate"><span class="pre">shape</span></code></a>,
which is a <a class="reference external" href="https://docs.python.org/dev/library/stdtypes.html#tuple" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">tuple</span></code></a> of <em>N</em> non-negative integers that specify the
sizes of each dimension. The type of items in the array is specified by
a separate <a class="reference internal" href="arrays.dtypes.html#arrays-dtypes"><span class="std std-ref">data-type object (dtype)</span></a>, one of which
is associated with each ndarray.</p>
<p>As with other container objects in Python, the contents of an
<a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> can be accessed and modified by <a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">indexing or
slicing</span></a> the array (using, for example, <em>N</em> integers),
and via the methods and attributes of the <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a>.</p>
<p id="index-0">Different <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarrays</span></code></a> can share the same data, so that
changes made in one <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> may be visible in another. That
is, an ndarray can be a <em>“view”</em> to another ndarray, and the data it
is referring to is taken care of by the <em>“base”</em> ndarray. ndarrays can
also be views to memory owned by Python <a class="reference external" href="https://docs.python.org/dev/library/stdtypes.html#str" title="(in Python v3.9)"><code class="xref py py-class docutils literal notranslate"><span class="pre">strings</span></code></a> or
objects implementing the <code class="xref py py-class docutils literal notranslate"><span class="pre">buffer</span></code> or <a class="reference internal" href="arrays.interface.html#arrays-interface"><span class="std std-ref">array</span></a> interfaces.</p>
<div class="admonition-example admonition">
<p class="admonition-title">Example</p>
<p>A 2-dimensional array of size 2 x 3, composed of 4-byte integer
elements:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]],</span> <span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">type</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">&lt;type &#39;numpy.ndarray&#39;&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(2, 3)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">dtype</span>
<span class="go">dtype(&#39;int32&#39;)</span>
</pre></div>
</div>
<p>The array can be indexed using Python container-like syntax:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="c1"># The element of x in the *second* row, *third* column, namely, 6.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span>
</pre></div>
</div>
<p>For example <a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">slicing</span></a> can produce views of
the array:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="p">[:,</span><span class="mi">1</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span>
<span class="go">array([2, 5])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">9</span> <span class="c1"># this also changes the corresponding element in x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span>
<span class="go">array([9, 5])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([[1, 9, 3],</span>
<span class="go">       [4, 5, 6]])</span>
</pre></div>
</div>
</div>
<div class="section" id="constructing-arrays">
<h2>Constructing arrays<a class="headerlink" href="#constructing-arrays" title="Permalink to this headline">¶</a></h2>
<p>New arrays can be constructed using the routines detailed in
<a class="reference internal" href="routines.array-creation.html#routines-array-creation"><span class="std std-ref">Array creation routines</span></a>, and also by using the low-level
<a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> constructor:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray</span></code></a>(shape[, dtype, buffer, offset, …])</p></td>
<td><p>An array object represents a multidimensional, homogeneous array of fixed-size items.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="indexing-arrays">
<span id="arrays-ndarray-indexing"></span><h2>Indexing arrays<a class="headerlink" href="#indexing-arrays" title="Permalink to this headline">¶</a></h2>
<p>Arrays can be indexed using an extended Python slicing syntax,
<code class="docutils literal notranslate"><span class="pre">array[selection]</span></code>.  Similar syntax is also used for accessing
fields in a <a class="reference internal" href="../glossary.html#term-structured-data-type"><span class="xref std std-term">structured data type</span></a>.</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">Array Indexing</span></a>.</p>
</div>
</div>
<div class="section" id="internal-memory-layout-of-an-ndarray">
<span id="memory-layout"></span><h2>Internal memory layout of an ndarray<a class="headerlink" href="#internal-memory-layout-of-an-ndarray" title="Permalink to this headline">¶</a></h2>
<p>An instance of class <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> consists of a contiguous
one-dimensional segment of computer memory (owned by the array, or by
some other object), combined with an indexing scheme that maps <em>N</em>
integers into the location of an item in the block.  The ranges in
which the indices can vary is specified by the <a class="reference internal" href="generated/numpy.ndarray.shape.html#numpy.ndarray.shape" title="numpy.ndarray.shape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">shape</span></code></a> of the array. How many bytes each item takes and how
the bytes are interpreted is defined by the <a class="reference internal" href="arrays.dtypes.html#arrays-dtypes"><span class="std std-ref">data-type object</span></a> associated with the array.</p>
<p id="index-1">A segment of memory is inherently 1-dimensional, and there are many
different schemes for arranging the items of an <em>N</em>-dimensional array
in a 1-dimensional block. NumPy is flexible, and <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a>
objects can accommodate any <em>strided indexing scheme</em>. In a strided
scheme, the N-dimensional index <img class="math" src="../_images/math/7bb829ee78ad04eb3c22dc7372e11d8bb1fa99fc.svg" alt="(n_0, n_1, ..., n_{N-1})"/>
corresponds to the offset (in bytes):</p>
<div class="math">
<p><img src="../_images/math/c63a38f3582b6c1c2e246f672eeeee67f20e2918.svg" alt="n_{\mathrm{offset}} = \sum_{k=0}^{N-1} s_k n_k"/></p>
</div><p>from the beginning of the memory block associated with the
array. Here, <img class="math" src="../_images/math/ff59e6547e68154d3e710b6982fdf954a770af75.svg" alt="s_k"/> are integers which specify the <a class="reference internal" href="generated/numpy.ndarray.strides.html#numpy.ndarray.strides" title="numpy.ndarray.strides"><code class="xref py py-obj docutils literal notranslate"><span class="pre">strides</span></code></a> of the array. The <a class="reference internal" href="../glossary.html#term-column-major"><span class="xref std std-term">column-major</span></a> order (used,
for example, in the Fortran language and in <em>Matlab</em>) and
<a class="reference internal" href="../glossary.html#term-row-major"><span class="xref std std-term">row-major</span></a> order (used in C) schemes are just specific kinds of
strided scheme, and correspond to memory that can be <em>addressed</em> by the strides:</p>
<div class="math">
<p><img src="../_images/math/22cd4fd6f85288feec822413cca12cc0c6bcf8b3.svg" alt="s_k^{\mathrm{column}} = \mathrm{itemsize} \prod_{j=0}^{k-1} d_j ,
\quad  s_k^{\mathrm{row}} = \mathrm{itemsize} \prod_{j=k+1}^{N-1} d_j ."/></p>
</div><p id="index-2">where <img class="math" src="../_images/math/40b2016b0a343a9ecd6b8c92a5dc4716f58cfe32.svg" alt="d_j"/> <em class="xref py py-obj">= self.shape[j]</em>.</p>
<p>Both the C and Fortran orders are <a class="reference external" href="https://docs.python.org/dev/glossary.html#term-contiguous" title="(in Python v3.9)"><span class="xref std std-term">contiguous</span></a>, <em>i.e.,</em>
single-segment, memory layouts, in which every part of the
memory block can be accessed by some combination of the indices.</p>
<p>While a C-style and Fortran-style contiguous array, which has the corresponding
flags set, can be addressed with the above strides, the actual strides may be
different. This can happen in two cases:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">self.shape[k]</span> <span class="pre">==</span> <span class="pre">1</span></code> then for any legal index <code class="docutils literal notranslate"><span class="pre">index[k]</span> <span class="pre">==</span> <span class="pre">0</span></code>.
This means that in the formula for the offset <img class="math" src="../_images/math/c89e851781410745c71c86ff80e293b149c8dacf.svg" alt="n_k = 0"/> and thus
<img class="math" src="../_images/math/e9e7529b18681d6993a2494e97da89c1e8f3447d.svg" alt="s_k n_k = 0"/> and the value of <img class="math" src="../_images/math/ff59e6547e68154d3e710b6982fdf954a770af75.svg" alt="s_k"/> <em class="xref py py-obj">= self.strides[k]</em> is
arbitrary.</p></li>
<li><p>If an array has no elements (<code class="docutils literal notranslate"><span class="pre">self.size</span> <span class="pre">==</span> <span class="pre">0</span></code>) there is no legal
index and the strides are never used. Any array with no elements may be
considered C-style and Fortran-style contiguous.</p></li>
</ol>
</div></blockquote>
<p>Point 1. means that <code class="docutils literal notranslate"><span class="pre">self</span></code> and <code class="docutils literal notranslate"><span class="pre">self.squeeze()</span></code> always have the same
contiguity and <code class="docutils literal notranslate"><span class="pre">aligned</span></code> flags value. This also means
that even a high dimensional array could be C-style and Fortran-style
contiguous at the same time.</p>
<p id="index-3">An array is considered aligned if the memory offsets for all elements and the
base offset itself is a multiple of <em class="xref py py-obj">self.itemsize</em>. Understanding
<em class="xref py py-obj">memory-alignment</em> leads to better performance on most hardware.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Points (1) and (2) are not yet applied by default. Beginning with
NumPy 1.8.0, they are applied consistently only if the environment
variable <code class="docutils literal notranslate"><span class="pre">NPY_RELAXED_STRIDES_CHECKING=1</span></code> was defined when NumPy
was built. Eventually this will become the default.</p>
<p>You can check whether this option was enabled when your NumPy was
built by looking at the value of <code class="docutils literal notranslate"><span class="pre">np.ones((10,1),</span>
<span class="pre">order='C').flags.f_contiguous</span></code>. If this is <code class="docutils literal notranslate"><span class="pre">True</span></code>, then your
NumPy has relaxed strides checking enabled.</p>
</div>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>It does <em>not</em> generally hold that <code class="docutils literal notranslate"><span class="pre">self.strides[-1]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span></code>
for C-style contiguous arrays or <code class="docutils literal notranslate"><span class="pre">self.strides[0]</span> <span class="pre">==</span> <span class="pre">self.itemsize</span></code> for
Fortran-style contiguous arrays is true.</p>
</div>
<p>Data in new <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarrays</span></code></a> is in the <a class="reference internal" href="../glossary.html#term-row-major"><span class="xref std std-term">row-major</span></a>
(C) order, unless otherwise specified, but, for example, <a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">basic
array slicing</span></a> often produces <a class="reference internal" href="../glossary.html#term-view"><span class="xref std std-term">views</span></a>
in a different scheme.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Several algorithms in NumPy work on arbitrarily strided arrays.
However, some algorithms require single-segment arrays. When an
irregularly strided array is passed in to such algorithms, a copy
is automatically made.</p>
</div>
</div>
<div class="section" id="array-attributes">
<span id="arrays-ndarray-attributes"></span><h2>Array attributes<a class="headerlink" href="#array-attributes" title="Permalink to this headline">¶</a></h2>
<p>Array attributes reflect information that is intrinsic to the array
itself. Generally, accessing an array through its attributes allows
you to get and sometimes set intrinsic properties of the array without
creating a new array. The exposed attributes are the core parts of an
array and only some of them can be reset meaningfully without creating
a new array. Information on each attribute is given below.</p>
<div class="section" id="id1">
<h3>Memory layout<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>The following attributes contain information about the memory layout
of the array:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.flags.html#numpy.ndarray.flags" title="numpy.ndarray.flags"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.flags</span></code></a></p></td>
<td><p>Information about the memory layout of the array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.shape.html#numpy.ndarray.shape" title="numpy.ndarray.shape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.shape</span></code></a></p></td>
<td><p>Tuple of array dimensions.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.strides.html#numpy.ndarray.strides" title="numpy.ndarray.strides"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.strides</span></code></a></p></td>
<td><p>Tuple of bytes to step in each dimension when traversing an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.ndim.html#numpy.ndarray.ndim" title="numpy.ndarray.ndim"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.ndim</span></code></a></p></td>
<td><p>Number of array dimensions.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.data.html#numpy.ndarray.data" title="numpy.ndarray.data"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.data</span></code></a></p></td>
<td><p>Python buffer object pointing to the start of the array’s data.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.size.html#numpy.ndarray.size" title="numpy.ndarray.size"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.size</span></code></a></p></td>
<td><p>Number of elements in the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.itemsize.html#numpy.ndarray.itemsize" title="numpy.ndarray.itemsize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.itemsize</span></code></a></p></td>
<td><p>Length of one array element in bytes.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.nbytes.html#numpy.ndarray.nbytes" title="numpy.ndarray.nbytes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.nbytes</span></code></a></p></td>
<td><p>Total bytes consumed by the elements of the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.base.html#numpy.ndarray.base" title="numpy.ndarray.base"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.base</span></code></a></p></td>
<td><p>Base object if memory is from some other object.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="data-type">
<h3>Data type<a class="headerlink" href="#data-type" title="Permalink to this headline">¶</a></h3>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="arrays.dtypes.html#arrays-dtypes"><span class="std std-ref">Data type objects</span></a></p>
</div>
<p>The data type object associated with the array can be found in the
<a class="reference internal" href="generated/numpy.ndarray.dtype.html#numpy.ndarray.dtype" title="numpy.ndarray.dtype"><code class="xref py py-attr docutils literal notranslate"><span class="pre">dtype</span></code></a> attribute:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.dtype.html#numpy.ndarray.dtype" title="numpy.ndarray.dtype"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.dtype</span></code></a></p></td>
<td><p>Data-type of the array’s elements.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="other-attributes">
<h3>Other attributes<a class="headerlink" href="#other-attributes" title="Permalink to this headline">¶</a></h3>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.T.html#numpy.ndarray.T" title="numpy.ndarray.T"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.T</span></code></a></p></td>
<td><p>The transposed array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.real.html#numpy.ndarray.real" title="numpy.ndarray.real"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.real</span></code></a></p></td>
<td><p>The real part of the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.imag.html#numpy.ndarray.imag" title="numpy.ndarray.imag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.imag</span></code></a></p></td>
<td><p>The imaginary part of the array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.flat.html#numpy.ndarray.flat" title="numpy.ndarray.flat"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.flat</span></code></a></p></td>
<td><p>A 1-D iterator over the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.ctypes.html#numpy.ndarray.ctypes" title="numpy.ndarray.ctypes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.ctypes</span></code></a></p></td>
<td><p>An object to simplify the interaction of the array with the ctypes module.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="array-interface">
<span id="arrays-ndarray-array-interface"></span><h3>Array interface<a class="headerlink" href="#array-interface" title="Permalink to this headline">¶</a></h3>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="arrays.interface.html#arrays-interface"><span class="std std-ref">The Array Interface</span></a>.</p>
</div>
<table class="docutils align-default">
<colgroup>
<col style="width: 43%" />
<col style="width: 57%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="arrays.interface.html#__array_interface__" title="__array_interface__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_interface__</span></code></a></p></td>
<td><p>Python-side of the array interface</p></td>
</tr>
<tr class="row-even"><td><p><code class="xref py py-obj docutils literal notranslate"><span class="pre">__array_struct__</span></code></p></td>
<td><p>C-side of the array interface</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="ctypes-foreign-function-interface">
<h3><a class="reference external" href="https://docs.python.org/dev/library/ctypes.html#module-ctypes" title="(in Python v3.9)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ctypes</span></code></a> foreign function interface<a class="headerlink" href="#ctypes-foreign-function-interface" title="Permalink to this headline">¶</a></h3>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.ctypes.html#numpy.ndarray.ctypes" title="numpy.ndarray.ctypes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.ctypes</span></code></a></p></td>
<td><p>An object to simplify the interaction of the array with the ctypes module.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="array-methods">
<span id="array-ndarray-methods"></span><h2>Array methods<a class="headerlink" href="#array-methods" title="Permalink to this headline">¶</a></h2>
<p>An <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> object has many methods which operate on or with
the array in some fashion, typically returning an array result. These
methods are briefly explained below. (Each method’s docstring has a
more complete description.)</p>
<p>For the following methods there are also corresponding functions in
<a class="reference internal" href="index.html#module-numpy" title="numpy"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy</span></code></a>: <a class="reference internal" href="generated/numpy.all.html#numpy.all" title="numpy.all"><code class="xref py py-func docutils literal notranslate"><span class="pre">all</span></code></a>, <a class="reference internal" href="generated/numpy.any.html#numpy.any" title="numpy.any"><code class="xref py py-func docutils literal notranslate"><span class="pre">any</span></code></a>, <a class="reference internal" href="generated/numpy.argmax.html#numpy.argmax" title="numpy.argmax"><code class="xref py py-func docutils literal notranslate"><span class="pre">argmax</span></code></a>,
<a class="reference internal" href="generated/numpy.argmin.html#numpy.argmin" title="numpy.argmin"><code class="xref py py-func docutils literal notranslate"><span class="pre">argmin</span></code></a>, <a class="reference internal" href="generated/numpy.argpartition.html#numpy.argpartition" title="numpy.argpartition"><code class="xref py py-func docutils literal notranslate"><span class="pre">argpartition</span></code></a>, <a class="reference internal" href="generated/numpy.argsort.html#numpy.argsort" title="numpy.argsort"><code class="xref py py-func docutils literal notranslate"><span class="pre">argsort</span></code></a>, <a class="reference internal" href="generated/numpy.choose.html#numpy.choose" title="numpy.choose"><code class="xref py py-func docutils literal notranslate"><span class="pre">choose</span></code></a>,
<a class="reference internal" href="generated/numpy.clip.html#numpy.clip" title="numpy.clip"><code class="xref py py-func docutils literal notranslate"><span class="pre">clip</span></code></a>, <a class="reference internal" href="generated/numpy.compress.html#numpy.compress" title="numpy.compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">compress</span></code></a>, <a class="reference internal" href="generated/numpy.copy.html#numpy.copy" title="numpy.copy"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy</span></code></a>, <a class="reference internal" href="generated/numpy.cumprod.html#numpy.cumprod" title="numpy.cumprod"><code class="xref py py-func docutils literal notranslate"><span class="pre">cumprod</span></code></a>,
<a class="reference internal" href="generated/numpy.cumsum.html#numpy.cumsum" title="numpy.cumsum"><code class="xref py py-func docutils literal notranslate"><span class="pre">cumsum</span></code></a>, <a class="reference internal" href="generated/numpy.diagonal.html#numpy.diagonal" title="numpy.diagonal"><code class="xref py py-func docutils literal notranslate"><span class="pre">diagonal</span></code></a>, <a class="reference internal" href="generated/numpy.imag.html#numpy.imag" title="numpy.imag"><code class="xref py py-func docutils literal notranslate"><span class="pre">imag</span></code></a>, <a class="reference internal" href="generated/numpy.amax.html#numpy.amax" title="numpy.amax"><code class="xref py py-func docutils literal notranslate"><span class="pre">max</span></code></a>,
<a class="reference internal" href="generated/numpy.mean.html#numpy.mean" title="numpy.mean"><code class="xref py py-func docutils literal notranslate"><span class="pre">mean</span></code></a>, <a class="reference internal" href="generated/numpy.amin.html#numpy.amin" title="numpy.amin"><code class="xref py py-func docutils literal notranslate"><span class="pre">min</span></code></a>, <a class="reference internal" href="generated/numpy.nonzero.html#numpy.nonzero" title="numpy.nonzero"><code class="xref py py-func docutils literal notranslate"><span class="pre">nonzero</span></code></a>, <a class="reference internal" href="generated/numpy.partition.html#numpy.partition" title="numpy.partition"><code class="xref py py-func docutils literal notranslate"><span class="pre">partition</span></code></a>,
<a class="reference internal" href="generated/numpy.prod.html#numpy.prod" title="numpy.prod"><code class="xref py py-func docutils literal notranslate"><span class="pre">prod</span></code></a>, <a class="reference internal" href="generated/numpy.ptp.html#numpy.ptp" title="numpy.ptp"><code class="xref py py-func docutils literal notranslate"><span class="pre">ptp</span></code></a>, <a class="reference internal" href="generated/numpy.put.html#numpy.put" title="numpy.put"><code class="xref py py-func docutils literal notranslate"><span class="pre">put</span></code></a>, <a class="reference internal" href="generated/numpy.ravel.html#numpy.ravel" title="numpy.ravel"><code class="xref py py-func docutils literal notranslate"><span class="pre">ravel</span></code></a>, <a class="reference internal" href="generated/numpy.real.html#numpy.real" title="numpy.real"><code class="xref py py-func docutils literal notranslate"><span class="pre">real</span></code></a>,
<a class="reference internal" href="generated/numpy.repeat.html#numpy.repeat" title="numpy.repeat"><code class="xref py py-func docutils literal notranslate"><span class="pre">repeat</span></code></a>, <a class="reference internal" href="generated/numpy.reshape.html#numpy.reshape" title="numpy.reshape"><code class="xref py py-func docutils literal notranslate"><span class="pre">reshape</span></code></a>, <a class="reference internal" href="generated/numpy.around.html#numpy.around" title="numpy.around"><code class="xref py py-func docutils literal notranslate"><span class="pre">round</span></code></a>,
<a class="reference internal" href="generated/numpy.searchsorted.html#numpy.searchsorted" title="numpy.searchsorted"><code class="xref py py-func docutils literal notranslate"><span class="pre">searchsorted</span></code></a>, <a class="reference internal" href="generated/numpy.sort.html#numpy.sort" title="numpy.sort"><code class="xref py py-func docutils literal notranslate"><span class="pre">sort</span></code></a>, <a class="reference internal" href="generated/numpy.squeeze.html#numpy.squeeze" title="numpy.squeeze"><code class="xref py py-func docutils literal notranslate"><span class="pre">squeeze</span></code></a>, <a class="reference internal" href="generated/numpy.std.html#numpy.std" title="numpy.std"><code class="xref py py-func docutils literal notranslate"><span class="pre">std</span></code></a>,
<a class="reference internal" href="generated/numpy.sum.html#numpy.sum" title="numpy.sum"><code class="xref py py-func docutils literal notranslate"><span class="pre">sum</span></code></a>, <a class="reference internal" href="generated/numpy.swapaxes.html#numpy.swapaxes" title="numpy.swapaxes"><code class="xref py py-func docutils literal notranslate"><span class="pre">swapaxes</span></code></a>, <a class="reference internal" href="generated/numpy.take.html#numpy.take" title="numpy.take"><code class="xref py py-func docutils literal notranslate"><span class="pre">take</span></code></a>, <a class="reference internal" href="generated/numpy.trace.html#numpy.trace" title="numpy.trace"><code class="xref py py-func docutils literal notranslate"><span class="pre">trace</span></code></a>,
<a class="reference internal" href="generated/numpy.transpose.html#numpy.transpose" title="numpy.transpose"><code class="xref py py-func docutils literal notranslate"><span class="pre">transpose</span></code></a>, <a class="reference internal" href="generated/numpy.var.html#numpy.var" title="numpy.var"><code class="xref py py-func docutils literal notranslate"><span class="pre">var</span></code></a>.</p>
<div class="section" id="array-conversion">
<h3>Array conversion<a class="headerlink" href="#array-conversion" title="Permalink to this headline">¶</a></h3>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.item.html#numpy.ndarray.item" title="numpy.ndarray.item"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.item</span></code></a>(*args)</p></td>
<td><p>Copy an element of an array to a standard Python scalar and return it.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.tolist.html#numpy.ndarray.tolist" title="numpy.ndarray.tolist"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.tolist</span></code></a>()</p></td>
<td><p>Return the array as an <code class="docutils literal notranslate"><span class="pre">a.ndim</span></code>-levels deep nested list of Python scalars.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.itemset.html#numpy.ndarray.itemset" title="numpy.ndarray.itemset"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.itemset</span></code></a>(*args)</p></td>
<td><p>Insert scalar into an array (scalar is cast to array’s dtype, if possible)</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.tostring.html#numpy.ndarray.tostring" title="numpy.ndarray.tostring"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.tostring</span></code></a>([order])</p></td>
<td><p>Construct Python bytes containing the raw data bytes in the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.tobytes.html#numpy.ndarray.tobytes" title="numpy.ndarray.tobytes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.tobytes</span></code></a>([order])</p></td>
<td><p>Construct Python bytes containing the raw data bytes in the array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.tofile.html#numpy.ndarray.tofile" title="numpy.ndarray.tofile"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.tofile</span></code></a>(fid[, sep, format])</p></td>
<td><p>Write array to a file as text or binary (default).</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.dump.html#numpy.ndarray.dump" title="numpy.ndarray.dump"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.dump</span></code></a>(file)</p></td>
<td><p>Dump a pickle of the array to the specified file.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.dumps.html#numpy.ndarray.dumps" title="numpy.ndarray.dumps"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.dumps</span></code></a>()</p></td>
<td><p>Returns the pickle of the array as a string.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.astype.html#numpy.ndarray.astype" title="numpy.ndarray.astype"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.astype</span></code></a>(dtype[, order, casting, …])</p></td>
<td><p>Copy of the array, cast to a specified type.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.byteswap.html#numpy.ndarray.byteswap" title="numpy.ndarray.byteswap"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.byteswap</span></code></a>([inplace])</p></td>
<td><p>Swap the bytes of the array elements</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.copy.html#numpy.ndarray.copy" title="numpy.ndarray.copy"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.copy</span></code></a>([order])</p></td>
<td><p>Return a copy of the array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.view.html#numpy.ndarray.view" title="numpy.ndarray.view"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.view</span></code></a>([dtype, type])</p></td>
<td><p>New view of array with the same data.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.getfield.html#numpy.ndarray.getfield" title="numpy.ndarray.getfield"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.getfield</span></code></a>(dtype[, offset])</p></td>
<td><p>Returns a field of the given array as a certain type.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.setflags.html#numpy.ndarray.setflags" title="numpy.ndarray.setflags"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.setflags</span></code></a>([write, align, uic])</p></td>
<td><p>Set array flags WRITEABLE, ALIGNED, (WRITEBACKIFCOPY and UPDATEIFCOPY), respectively.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.fill.html#numpy.ndarray.fill" title="numpy.ndarray.fill"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.fill</span></code></a>(value)</p></td>
<td><p>Fill the array with a scalar value.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="shape-manipulation">
<h3>Shape manipulation<a class="headerlink" href="#shape-manipulation" title="Permalink to this headline">¶</a></h3>
<p>For reshape, resize, and transpose, the single tuple argument may be
replaced with <code class="docutils literal notranslate"><span class="pre">n</span></code> integers which will be interpreted as an n-tuple.</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.reshape.html#numpy.ndarray.reshape" title="numpy.ndarray.reshape"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.reshape</span></code></a>(shape[, order])</p></td>
<td><p>Returns an array containing the same data with a new shape.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.resize.html#numpy.ndarray.resize" title="numpy.ndarray.resize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.resize</span></code></a>(new_shape[, refcheck])</p></td>
<td><p>Change shape and size of array in-place.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.transpose.html#numpy.ndarray.transpose" title="numpy.ndarray.transpose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.transpose</span></code></a>(*axes)</p></td>
<td><p>Returns a view of the array with axes transposed.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.swapaxes.html#numpy.ndarray.swapaxes" title="numpy.ndarray.swapaxes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.swapaxes</span></code></a>(axis1, axis2)</p></td>
<td><p>Return a view of the array with <em class="xref py py-obj">axis1</em> and <em class="xref py py-obj">axis2</em> interchanged.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.flatten.html#numpy.ndarray.flatten" title="numpy.ndarray.flatten"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.flatten</span></code></a>([order])</p></td>
<td><p>Return a copy of the array collapsed into one dimension.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.ravel.html#numpy.ndarray.ravel" title="numpy.ndarray.ravel"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.ravel</span></code></a>([order])</p></td>
<td><p>Return a flattened array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.squeeze.html#numpy.ndarray.squeeze" title="numpy.ndarray.squeeze"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.squeeze</span></code></a>([axis])</p></td>
<td><p>Remove single-dimensional entries from the shape of <em class="xref py py-obj">a</em>.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="item-selection-and-manipulation">
<h3>Item selection and manipulation<a class="headerlink" href="#item-selection-and-manipulation" title="Permalink to this headline">¶</a></h3>
<p>For array methods that take an <em>axis</em> keyword, it defaults to
<em>None</em>. If axis is <em>None</em>, then the array is treated as a 1-D
array. Any other value for <em>axis</em> represents the dimension along which
the operation should proceed.</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.take.html#numpy.ndarray.take" title="numpy.ndarray.take"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.take</span></code></a>(indices[, axis, out, mode])</p></td>
<td><p>Return an array formed from the elements of <em class="xref py py-obj">a</em> at the given indices.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.put.html#numpy.ndarray.put" title="numpy.ndarray.put"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.put</span></code></a>(indices, values[, mode])</p></td>
<td><p>Set <code class="docutils literal notranslate"><span class="pre">a.flat[n]</span> <span class="pre">=</span> <span class="pre">values[n]</span></code> for all <em class="xref py py-obj">n</em> in indices.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.repeat.html#numpy.ndarray.repeat" title="numpy.ndarray.repeat"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.repeat</span></code></a>(repeats[, axis])</p></td>
<td><p>Repeat elements of an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.choose.html#numpy.ndarray.choose" title="numpy.ndarray.choose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.choose</span></code></a>(choices[, out, mode])</p></td>
<td><p>Use an index array to construct a new array from a set of choices.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.sort.html#numpy.ndarray.sort" title="numpy.ndarray.sort"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.sort</span></code></a>([axis, kind, order])</p></td>
<td><p>Sort an array in-place.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.argsort.html#numpy.ndarray.argsort" title="numpy.ndarray.argsort"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.argsort</span></code></a>([axis, kind, order])</p></td>
<td><p>Returns the indices that would sort this array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.partition.html#numpy.ndarray.partition" title="numpy.ndarray.partition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.partition</span></code></a>(kth[, axis, kind, order])</p></td>
<td><p>Rearranges the elements in the array in such a way that the value of the element in kth position is in the position it would be in a sorted array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.argpartition.html#numpy.ndarray.argpartition" title="numpy.ndarray.argpartition"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.argpartition</span></code></a>(kth[, axis, kind, order])</p></td>
<td><p>Returns the indices that would partition this array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.searchsorted.html#numpy.ndarray.searchsorted" title="numpy.ndarray.searchsorted"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.searchsorted</span></code></a>(v[, side, sorter])</p></td>
<td><p>Find indices where elements of v should be inserted in a to maintain order.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.nonzero.html#numpy.ndarray.nonzero" title="numpy.ndarray.nonzero"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.nonzero</span></code></a>()</p></td>
<td><p>Return the indices of the elements that are non-zero.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.compress.html#numpy.ndarray.compress" title="numpy.ndarray.compress"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.compress</span></code></a>(condition[, axis, out])</p></td>
<td><p>Return selected slices of this array along given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.diagonal.html#numpy.ndarray.diagonal" title="numpy.ndarray.diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.diagonal</span></code></a>([offset, axis1, axis2])</p></td>
<td><p>Return specified diagonals.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="calculation">
<h3>Calculation<a class="headerlink" href="#calculation" title="Permalink to this headline">¶</a></h3>
<p id="index-4">Many of these methods take an argument named <em>axis</em>. In such cases,</p>
<ul class="simple">
<li><p>If <em>axis</em> is <em>None</em> (the default), the array is treated as a 1-D
array and the operation is performed over the entire array. This
behavior is also the default if self is a 0-dimensional array or
array scalar. (An array scalar is an instance of the types/classes
float32, float64, etc., whereas a 0-dimensional array is an ndarray
instance containing precisely one array scalar.)</p></li>
<li><p>If <em>axis</em> is an integer, then the operation is done over the given
axis (for each 1-D subarray that can be created along the given axis).</p></li>
</ul>
<div class="admonition-example-of-the-axis-argument admonition">
<p class="admonition-title">Example of the <em>axis</em> argument</p>
<p>A 3-dimensional array of size 3 x 3 x 3, summed over each of its
three axes</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([[[ 0,  1,  2],</span>
<span class="go">        [ 3,  4,  5],</span>
<span class="go">        [ 6,  7,  8]],</span>
<span class="go">       [[ 9, 10, 11],</span>
<span class="go">        [12, 13, 14],</span>
<span class="go">        [15, 16, 17]],</span>
<span class="go">       [[18, 19, 20],</span>
<span class="go">        [21, 22, 23],</span>
<span class="go">        [24, 25, 26]]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="go">array([[27, 30, 33],</span>
<span class="go">       [36, 39, 42],</span>
<span class="go">       [45, 48, 51]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># for sum, axis is the first keyword, so we may omit it,</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># specifying only its value</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mi">0</span><span class="p">),</span> <span class="n">x</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span> <span class="n">x</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">(array([[27, 30, 33],</span>
<span class="go">        [36, 39, 42],</span>
<span class="go">        [45, 48, 51]]),</span>
<span class="go"> array([[ 9, 12, 15],</span>
<span class="go">        [36, 39, 42],</span>
<span class="go">        [63, 66, 69]]),</span>
<span class="go"> array([[ 3, 12, 21],</span>
<span class="go">        [30, 39, 48],</span>
<span class="go">        [57, 66, 75]]))</span>
</pre></div>
</div>
</div>
<p>The parameter <em>dtype</em> specifies the data type over which a reduction
operation (like summing) should take place. The default reduce data
type is the same as the data type of <em>self</em>. To avoid overflow, it can
be useful to perform the reduction using a larger data type.</p>
<p>For several methods, an optional <em>out</em> argument can also be provided
and the result will be placed into the output array given. The <em>out</em>
argument must be an <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> and have the same number of
elements. It can have a different data type in which case casting will
be performed.</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.max.html#numpy.ndarray.max" title="numpy.ndarray.max"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.max</span></code></a>([axis, out, keepdims, initial, …])</p></td>
<td><p>Return the maximum along a given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.argmax.html#numpy.ndarray.argmax" title="numpy.ndarray.argmax"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.argmax</span></code></a>([axis, out])</p></td>
<td><p>Return indices of the maximum values along the given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.min.html#numpy.ndarray.min" title="numpy.ndarray.min"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.min</span></code></a>([axis, out, keepdims, initial, …])</p></td>
<td><p>Return the minimum along a given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.argmin.html#numpy.ndarray.argmin" title="numpy.ndarray.argmin"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.argmin</span></code></a>([axis, out])</p></td>
<td><p>Return indices of the minimum values along the given axis of <em class="xref py py-obj">a</em>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.ptp.html#numpy.ndarray.ptp" title="numpy.ndarray.ptp"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.ptp</span></code></a>([axis, out, keepdims])</p></td>
<td><p>Peak to peak (maximum - minimum) value along a given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.clip.html#numpy.ndarray.clip" title="numpy.ndarray.clip"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.clip</span></code></a>([min, max, out])</p></td>
<td><p>Return an array whose values are limited to <code class="docutils literal notranslate"><span class="pre">[min,</span> <span class="pre">max]</span></code>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.conj.html#numpy.ndarray.conj" title="numpy.ndarray.conj"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.conj</span></code></a>()</p></td>
<td><p>Complex-conjugate all elements.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.round.html#numpy.ndarray.round" title="numpy.ndarray.round"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.round</span></code></a>([decimals, out])</p></td>
<td><p>Return <em class="xref py py-obj">a</em> with each element rounded to the given number of decimals.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.trace.html#numpy.ndarray.trace" title="numpy.ndarray.trace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.trace</span></code></a>([offset, axis1, axis2, dtype, out])</p></td>
<td><p>Return the sum along diagonals of the array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.sum.html#numpy.ndarray.sum" title="numpy.ndarray.sum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.sum</span></code></a>([axis, dtype, out, keepdims, …])</p></td>
<td><p>Return the sum of the array elements over the given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.cumsum.html#numpy.ndarray.cumsum" title="numpy.ndarray.cumsum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.cumsum</span></code></a>([axis, dtype, out])</p></td>
<td><p>Return the cumulative sum of the elements along the given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.mean.html#numpy.ndarray.mean" title="numpy.ndarray.mean"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.mean</span></code></a>([axis, dtype, out, keepdims])</p></td>
<td><p>Returns the average of the array elements along given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.var.html#numpy.ndarray.var" title="numpy.ndarray.var"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.var</span></code></a>([axis, dtype, out, ddof, keepdims])</p></td>
<td><p>Returns the variance of the array elements, along given axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.std.html#numpy.ndarray.std" title="numpy.ndarray.std"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.std</span></code></a>([axis, dtype, out, ddof, keepdims])</p></td>
<td><p>Returns the standard deviation of the array elements along given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.prod.html#numpy.ndarray.prod" title="numpy.ndarray.prod"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.prod</span></code></a>([axis, dtype, out, keepdims, …])</p></td>
<td><p>Return the product of the array elements over the given axis</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.cumprod.html#numpy.ndarray.cumprod" title="numpy.ndarray.cumprod"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.cumprod</span></code></a>([axis, dtype, out])</p></td>
<td><p>Return the cumulative product of the elements along the given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.all.html#numpy.ndarray.all" title="numpy.ndarray.all"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.all</span></code></a>([axis, out, keepdims])</p></td>
<td><p>Returns True if all elements evaluate to True.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.any.html#numpy.ndarray.any" title="numpy.ndarray.any"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.any</span></code></a>([axis, out, keepdims])</p></td>
<td><p>Returns True if any of the elements of <em class="xref py py-obj">a</em> evaluate to True.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="arithmetic-matrix-multiplication-and-comparison-operations">
<h2>Arithmetic, matrix multiplication, and comparison operations<a class="headerlink" href="#arithmetic-matrix-multiplication-and-comparison-operations" title="Permalink to this headline">¶</a></h2>
<p id="index-5">Arithmetic and comparison operations on <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarrays</span></code></a>
are defined as element-wise operations, and generally yield
<a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> objects as results.</p>
<p>Each of the arithmetic operations (<code class="docutils literal notranslate"><span class="pre">+</span></code>, <code class="docutils literal notranslate"><span class="pre">-</span></code>, <code class="docutils literal notranslate"><span class="pre">*</span></code>, <code class="docutils literal notranslate"><span class="pre">/</span></code>, <code class="docutils literal notranslate"><span class="pre">//</span></code>,
<code class="docutils literal notranslate"><span class="pre">%</span></code>, <code class="docutils literal notranslate"><span class="pre">divmod()</span></code>, <code class="docutils literal notranslate"><span class="pre">**</span></code> or <code class="docutils literal notranslate"><span class="pre">pow()</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;&lt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;&gt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&amp;</span></code>,
<code class="docutils literal notranslate"><span class="pre">^</span></code>, <code class="docutils literal notranslate"><span class="pre">|</span></code>, <code class="docutils literal notranslate"><span class="pre">~</span></code>) and the comparisons (<code class="docutils literal notranslate"><span class="pre">==</span></code>, <code class="docutils literal notranslate"><span class="pre">&lt;</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;</span></code>,
<code class="docutils literal notranslate"><span class="pre">&lt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">&gt;=</span></code>, <code class="docutils literal notranslate"><span class="pre">!=</span></code>) is equivalent to the corresponding
universal function (or <a class="reference internal" href="../glossary.html#term-ufunc"><span class="xref std std-term">ufunc</span></a> for short) in NumPy.  For
more information, see the section on <a class="reference internal" href="ufuncs.html#ufuncs"><span class="std std-ref">Universal Functions</span></a>.</p>
<p>Comparison operators:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__lt__.html#numpy.ndarray.__lt__" title="numpy.ndarray.__lt__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__lt__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&lt;value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__le__.html#numpy.ndarray.__le__" title="numpy.ndarray.__le__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__le__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&lt;=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__gt__.html#numpy.ndarray.__gt__" title="numpy.ndarray.__gt__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__gt__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&gt;value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ge__.html#numpy.ndarray.__ge__" title="numpy.ndarray.__ge__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ge__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&gt;=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__eq__.html#numpy.ndarray.__eq__" title="numpy.ndarray.__eq__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__eq__</span></code></a>(self, value, /)</p></td>
<td><p>Return self==value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ne__.html#numpy.ndarray.__ne__" title="numpy.ndarray.__ne__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ne__</span></code></a>(self, value, /)</p></td>
<td><p>Return self!=value.</p></td>
</tr>
</tbody>
</table>
<p>Truth value of an array (<code class="xref py py-func docutils literal notranslate"><span class="pre">bool</span></code>):</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__bool__.html#numpy.ndarray.__bool__" title="numpy.ndarray.__bool__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__bool__</span></code></a>(self, /)</p></td>
<td><p>self != 0</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Truth-value testing of an array invokes
<a class="reference internal" href="generated/numpy.ndarray.__bool__.html#numpy.ndarray.__bool__" title="numpy.ndarray.__bool__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ndarray.__bool__</span></code></a>, which raises an error if the number of
elements in the array is larger than 1, because the truth value
of such arrays is ambiguous. Use <a class="reference internal" href="generated/numpy.ndarray.any.html#numpy.ndarray.any" title="numpy.ndarray.any"><code class="xref py py-meth docutils literal notranslate"><span class="pre">.any()</span></code></a> and
<a class="reference internal" href="generated/numpy.ndarray.all.html#numpy.ndarray.all" title="numpy.ndarray.all"><code class="xref py py-meth docutils literal notranslate"><span class="pre">.all()</span></code></a> instead to be clear about what is meant
in such cases. (If the number of elements is 0, the array evaluates
to <code class="docutils literal notranslate"><span class="pre">False</span></code>.)</p>
</div>
<p>Unary operations:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__neg__.html#numpy.ndarray.__neg__" title="numpy.ndarray.__neg__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__neg__</span></code></a>(self, /)</p></td>
<td><p>-self</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__pos__.html#numpy.ndarray.__pos__" title="numpy.ndarray.__pos__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__pos__</span></code></a>(self, /)</p></td>
<td><p>+self</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__abs__.html#numpy.ndarray.__abs__" title="numpy.ndarray.__abs__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__abs__</span></code></a>(self)</p></td>
<td><p></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__invert__.html#numpy.ndarray.__invert__" title="numpy.ndarray.__invert__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__invert__</span></code></a>(self, /)</p></td>
<td><p>~self</p></td>
</tr>
</tbody>
</table>
<p>Arithmetic:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__add__.html#numpy.ndarray.__add__" title="numpy.ndarray.__add__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__add__</span></code></a>(self, value, /)</p></td>
<td><p>Return self+value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__sub__.html#numpy.ndarray.__sub__" title="numpy.ndarray.__sub__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__sub__</span></code></a>(self, value, /)</p></td>
<td><p>Return self-value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__mul__.html#numpy.ndarray.__mul__" title="numpy.ndarray.__mul__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__mul__</span></code></a>(self, value, /)</p></td>
<td><p>Return self*value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__truediv__.html#numpy.ndarray.__truediv__" title="numpy.ndarray.__truediv__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__truediv__</span></code></a>(self, value, /)</p></td>
<td><p>Return self/value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__floordiv__.html#numpy.ndarray.__floordiv__" title="numpy.ndarray.__floordiv__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__floordiv__</span></code></a>(self, value, /)</p></td>
<td><p>Return self//value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__mod__.html#numpy.ndarray.__mod__" title="numpy.ndarray.__mod__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__mod__</span></code></a>(self, value, /)</p></td>
<td><p>Return self%value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__divmod__.html#numpy.ndarray.__divmod__" title="numpy.ndarray.__divmod__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__divmod__</span></code></a>(self, value, /)</p></td>
<td><p>Return divmod(self, value).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__pow__.html#numpy.ndarray.__pow__" title="numpy.ndarray.__pow__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__pow__</span></code></a>(self, value[, mod])</p></td>
<td><p>Return pow(self, value, mod).</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__lshift__.html#numpy.ndarray.__lshift__" title="numpy.ndarray.__lshift__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__lshift__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&lt;&lt;value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__rshift__.html#numpy.ndarray.__rshift__" title="numpy.ndarray.__rshift__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__rshift__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&gt;&gt;value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__and__.html#numpy.ndarray.__and__" title="numpy.ndarray.__and__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__and__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&amp;value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__or__.html#numpy.ndarray.__or__" title="numpy.ndarray.__or__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__or__</span></code></a>(self, value, /)</p></td>
<td><p>Return self|value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__xor__.html#numpy.ndarray.__xor__" title="numpy.ndarray.__xor__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__xor__</span></code></a>(self, value, /)</p></td>
<td><p>Return self^value.</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<ul class="simple">
<li><p>Any third argument to <a class="reference external" href="https://docs.python.org/dev/library/functions.html#pow" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">pow</span></code></a> is silently ignored,
as the underlying <a class="reference internal" href="generated/numpy.power.html#numpy.power" title="numpy.power"><code class="xref py py-func docutils literal notranslate"><span class="pre">ufunc</span></code></a> takes only two arguments.</p></li>
<li><p>The three division operators are all defined; <code class="xref py py-obj docutils literal notranslate"><span class="pre">div</span></code> is active
by default, <code class="xref py py-obj docutils literal notranslate"><span class="pre">truediv</span></code> is active when
<a class="reference external" href="https://docs.python.org/dev/library/__future__.html#module-__future__" title="(in Python v3.9)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">__future__</span></code></a> division is in effect.</p></li>
<li><p>Because <a class="reference internal" href="generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray"><code class="xref py py-class docutils literal notranslate"><span class="pre">ndarray</span></code></a> is a built-in type (written in C), the
<code class="docutils literal notranslate"><span class="pre">__r{op}__</span></code> special methods are not directly defined.</p></li>
<li><p>The functions called to implement many arithmetic special methods
for arrays can be modified using <a class="reference internal" href="arrays.classes.html#numpy.class.__array_ufunc__" title="numpy.class.__array_ufunc__"><code class="xref py py-class docutils literal notranslate"><span class="pre">__array_ufunc__</span></code></a>.</p></li>
</ul>
</div>
<p>Arithmetic, in-place:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__iadd__.html#numpy.ndarray.__iadd__" title="numpy.ndarray.__iadd__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__iadd__</span></code></a>(self, value, /)</p></td>
<td><p>Return self+=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__isub__.html#numpy.ndarray.__isub__" title="numpy.ndarray.__isub__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__isub__</span></code></a>(self, value, /)</p></td>
<td><p>Return self-=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__imul__.html#numpy.ndarray.__imul__" title="numpy.ndarray.__imul__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__imul__</span></code></a>(self, value, /)</p></td>
<td><p>Return self*=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__itruediv__.html#numpy.ndarray.__itruediv__" title="numpy.ndarray.__itruediv__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__itruediv__</span></code></a>(self, value, /)</p></td>
<td><p>Return self/=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ifloordiv__.html#numpy.ndarray.__ifloordiv__" title="numpy.ndarray.__ifloordiv__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ifloordiv__</span></code></a>(self, value, /)</p></td>
<td><p>Return self//=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__imod__.html#numpy.ndarray.__imod__" title="numpy.ndarray.__imod__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__imod__</span></code></a>(self, value, /)</p></td>
<td><p>Return self%=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ipow__.html#numpy.ndarray.__ipow__" title="numpy.ndarray.__ipow__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ipow__</span></code></a>(self, value, /)</p></td>
<td><p>Return self**=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ilshift__.html#numpy.ndarray.__ilshift__" title="numpy.ndarray.__ilshift__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ilshift__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&lt;&lt;=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__irshift__.html#numpy.ndarray.__irshift__" title="numpy.ndarray.__irshift__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__irshift__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&gt;&gt;=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__iand__.html#numpy.ndarray.__iand__" title="numpy.ndarray.__iand__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__iand__</span></code></a>(self, value, /)</p></td>
<td><p>Return self&amp;=value.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ior__.html#numpy.ndarray.__ior__" title="numpy.ndarray.__ior__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ior__</span></code></a>(self, value, /)</p></td>
<td><p>Return self|=value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__ixor__.html#numpy.ndarray.__ixor__" title="numpy.ndarray.__ixor__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__ixor__</span></code></a>(self, value, /)</p></td>
<td><p>Return self^=value.</p></td>
</tr>
</tbody>
</table>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>In place operations will perform the calculation using the
precision decided by the data type of the two operands, but will
silently downcast the result (if necessary) so it can fit back into
the array.  Therefore, for mixed precision calculations, <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">{op}=</span>
<span class="pre">B</span></code> can be different than <code class="docutils literal notranslate"><span class="pre">A</span> <span class="pre">=</span> <span class="pre">A</span> <span class="pre">{op}</span> <span class="pre">B</span></code>. For example, suppose
<code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">ones((3,3))</span></code>. Then, <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+=</span> <span class="pre">3j</span></code> is different than <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">a</span> <span class="pre">+</span>
<span class="pre">3j</span></code>: while they both perform the same computation, <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+=</span> <span class="pre">3</span></code>
casts the result to fit back in <code class="docutils literal notranslate"><span class="pre">a</span></code>, whereas <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">=</span> <span class="pre">a</span> <span class="pre">+</span> <span class="pre">3j</span></code>
re-binds the name <code class="docutils literal notranslate"><span class="pre">a</span></code> to the result.</p>
</div>
<p>Matrix Multiplication:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__matmul__.html#numpy.ndarray.__matmul__" title="numpy.ndarray.__matmul__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__matmul__</span></code></a>(self, value, /)</p></td>
<td><p>Return <a class="reference external" href="mailto:self&#37;&#52;&#48;value">self<span>&#64;</span>value</a>.</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Matrix operators <code class="docutils literal notranslate"><span class="pre">&#64;</span></code> and <code class="docutils literal notranslate"><span class="pre">&#64;=</span></code> were introduced in Python 3.5
following PEP465. NumPy 1.10.0 has a preliminary implementation of <code class="docutils literal notranslate"><span class="pre">&#64;</span></code>
for testing purposes. Further documentation can be found in the
<a class="reference internal" href="generated/numpy.matmul.html#numpy.matmul" title="numpy.matmul"><code class="xref py py-func docutils literal notranslate"><span class="pre">matmul</span></code></a> documentation.</p>
</div>
</div>
<div class="section" id="special-methods">
<h2>Special methods<a class="headerlink" href="#special-methods" title="Permalink to this headline">¶</a></h2>
<p>For standard library functions:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__copy__.html#numpy.ndarray.__copy__" title="numpy.ndarray.__copy__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__copy__</span></code></a>()</p></td>
<td><p>Used if <a class="reference external" href="https://docs.python.org/dev/library/copy.html#copy.copy" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.copy</span></code></a> is called on an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__deepcopy__.html#numpy.ndarray.__deepcopy__" title="numpy.ndarray.__deepcopy__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__deepcopy__</span></code></a>()</p></td>
<td><p>Used if <a class="reference external" href="https://docs.python.org/dev/library/copy.html#copy.deepcopy" title="(in Python v3.9)"><code class="xref py py-func docutils literal notranslate"><span class="pre">copy.deepcopy</span></code></a> is called on an array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__reduce__.html#numpy.ndarray.__reduce__" title="numpy.ndarray.__reduce__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__reduce__</span></code></a>()</p></td>
<td><p>For pickling.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__setstate__.html#numpy.ndarray.__setstate__" title="numpy.ndarray.__setstate__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__setstate__</span></code></a>(state, /)</p></td>
<td><p>For unpickling.</p></td>
</tr>
</tbody>
</table>
<p>Basic customization:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__new__.html#numpy.ndarray.__new__" title="numpy.ndarray.__new__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__new__</span></code></a>(\*args, \*\*kwargs)</p></td>
<td><p>Create and return a new object.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__array__.html#numpy.ndarray.__array__" title="numpy.ndarray.__array__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__array__</span></code></a>()</p></td>
<td><p>Returns either a new reference to self if dtype is not given or a new array of provided data type if dtype is different from the current dtype of the array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__array_wrap__.html#numpy.ndarray.__array_wrap__" title="numpy.ndarray.__array_wrap__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__array_wrap__</span></code></a>()</p></td>
<td><p></p></td>
</tr>
</tbody>
</table>
<p>Container customization: (see <a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">Indexing</span></a>)</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__len__.html#numpy.ndarray.__len__" title="numpy.ndarray.__len__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__len__</span></code></a>(self, /)</p></td>
<td><p>Return len(self).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__getitem__.html#numpy.ndarray.__getitem__" title="numpy.ndarray.__getitem__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__getitem__</span></code></a>(self, key, /)</p></td>
<td><p>Return self[key].</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__setitem__.html#numpy.ndarray.__setitem__" title="numpy.ndarray.__setitem__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__setitem__</span></code></a>(self, key, value, /)</p></td>
<td><p>Set self[key] to value.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__contains__.html#numpy.ndarray.__contains__" title="numpy.ndarray.__contains__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__contains__</span></code></a>(self, key, /)</p></td>
<td><p>Return key in self.</p></td>
</tr>
</tbody>
</table>
<p>Conversion; the operations <code class="xref py py-func docutils literal notranslate"><span class="pre">int</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">float</span></code> and
<code class="xref py py-func docutils literal notranslate"><span class="pre">complex</span></code>.
. They work only on arrays that have one element in them
and return the appropriate scalar.</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__int__.html#numpy.ndarray.__int__" title="numpy.ndarray.__int__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__int__</span></code></a>(self)</p></td>
<td><p></p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__float__.html#numpy.ndarray.__float__" title="numpy.ndarray.__float__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__float__</span></code></a>(self)</p></td>
<td><p></p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__complex__.html#numpy.ndarray.__complex__" title="numpy.ndarray.__complex__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__complex__</span></code></a>()</p></td>
<td><p></p></td>
</tr>
</tbody>
</table>
<p>String representations:</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndarray.__str__.html#numpy.ndarray.__str__" title="numpy.ndarray.__str__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__str__</span></code></a>(self, /)</p></td>
<td><p>Return str(self).</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndarray.__repr__.html#numpy.ndarray.__repr__" title="numpy.ndarray.__repr__"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndarray.__repr__</span></code></a>(self, /)</p></td>
<td><p>Return repr(self).</p></td>
</tr>
</tbody>
</table>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>